package com.ruoyi.report_tg.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.DealHeh;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_tg.domain.bo.TdmdjlbBsInfoBo;
import com.ruoyi.report_tg.domain.vo.TdmdjlbBsInfoVo;
import com.ruoyi.report_tg.domain.TdmdjlbBsInfo;
import com.ruoyi.report_tg.mapper.TdmdjlbBsInfoMapper;
import com.ruoyi.report_tg.service.ITdmdjlbBsInfoService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 土的密度记录Service业务层处理
 *
 * @author zyb
 * @date 2024-05-24
 */
@RequiredArgsConstructor
@Service
@Transactional
public class TdmdjlbBsInfoServiceImpl implements ITdmdjlbBsInfoService {

    private final TdmdjlbBsInfoMapper baseMapper;

    /**
     * 查询土的密度记录
     */
    @Override
    @FIllBasicInfo
    public TdmdjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询土的密度记录列表
     */
    @Override
    public TableDataInfo<TdmdjlbBsInfoVo> queryPageList(TdmdjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<TdmdjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<TdmdjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询土的密度记录列表
     */
    @Override
    public List<TdmdjlbBsInfoVo> queryList(TdmdjlbBsInfoBo bo) {
        LambdaQueryWrapper<TdmdjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<TdmdjlbBsInfo> buildQueryWrapper(TdmdjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<TdmdjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, TdmdjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, TdmdjlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), TdmdjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), TdmdjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), TdmdjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), TdmdjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), TdmdjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), TdmdjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), TdmdjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getYangpsj() != null, TdmdjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), TdmdjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), TdmdjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), TdmdjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), TdmdjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), TdmdjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), TdmdjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getQuyzh1()), TdmdjlbBsInfo::getQuyzh1, bo.getQuyzh1());
        lqw.eq(StringUtils.isNotBlank(bo.getQuywz1()), TdmdjlbBsInfo::getQuywz1, bo.getQuywz1());
        lqw.eq(bo.getQuysd1() != null, TdmdjlbBsInfo::getQuysd1, bo.getQuysd1());
        lqw.eq(bo.getShiqtszl1() != null, TdmdjlbBsInfo::getShiqtszl1, bo.getShiqtszl1());
        lqw.eq(bo.getShihtjsyszl1() != null, TdmdjlbBsInfo::getShihtjsyszl1, bo.getShihtjsyszl1());
        lqw.eq(bo.getShiknszl1() != null, TdmdjlbBsInfo::getShiknszl1, bo.getShiknszl1());
        lqw.eq(bo.getLiangsmd1() != null, TdmdjlbBsInfo::getLiangsmd1, bo.getLiangsmd1());
        lqw.eq(bo.getShiktj1() != null, TdmdjlbBsInfo::getShiktj1, bo.getShiktj1());
        lqw.eq(bo.getKengnstyzl1() != null, TdmdjlbBsInfo::getKengnstyzl1, bo.getKengnstyzl1());
        lqw.eq(bo.getShimd1() != null, TdmdjlbBsInfo::getShimd1, bo.getShimd1());
        lqw.eq(StringUtils.isNotBlank(bo.getQuyzh2()), TdmdjlbBsInfo::getQuyzh2, bo.getQuyzh2());
        lqw.eq(StringUtils.isNotBlank(bo.getQuywz2()), TdmdjlbBsInfo::getQuywz2, bo.getQuywz2());
        lqw.eq(bo.getQuysd2() != null, TdmdjlbBsInfo::getQuysd2, bo.getQuysd2());
        lqw.eq(bo.getShiqtszl2() != null, TdmdjlbBsInfo::getShiqtszl2, bo.getShiqtszl2());
        lqw.eq(bo.getShihtjsyszl2() != null, TdmdjlbBsInfo::getShihtjsyszl2, bo.getShihtjsyszl2());
        lqw.eq(bo.getShiknszl2() != null, TdmdjlbBsInfo::getShiknszl2, bo.getShiknszl2());
        lqw.eq(bo.getLiangsmd2() != null, TdmdjlbBsInfo::getLiangsmd2, bo.getLiangsmd2());
        lqw.eq(bo.getShiktj2() != null, TdmdjlbBsInfo::getShiktj2, bo.getShiktj2());
        lqw.eq(bo.getKengnstyzl2() != null, TdmdjlbBsInfo::getKengnstyzl2, bo.getKengnstyzl2());
        lqw.eq(bo.getShimd2() != null, TdmdjlbBsInfo::getShimd2, bo.getShimd2());
        lqw.eq(StringUtils.isNotBlank(bo.getQuyzh3()), TdmdjlbBsInfo::getQuyzh3, bo.getQuyzh3());
        lqw.eq(StringUtils.isNotBlank(bo.getQuywz3()), TdmdjlbBsInfo::getQuywz3, bo.getQuywz3());
        lqw.eq(bo.getQuysd3() != null, TdmdjlbBsInfo::getQuysd3, bo.getQuysd3());
        lqw.eq(bo.getShiqtszl3() != null, TdmdjlbBsInfo::getShiqtszl3, bo.getShiqtszl3());
        lqw.eq(bo.getShihtjsyszl3() != null, TdmdjlbBsInfo::getShihtjsyszl3, bo.getShihtjsyszl3());
        lqw.eq(bo.getShiknszl3() != null, TdmdjlbBsInfo::getShiknszl3, bo.getShiknszl3());
        lqw.eq(bo.getLiangsmd3() != null, TdmdjlbBsInfo::getLiangsmd3, bo.getLiangsmd3());
        lqw.eq(bo.getShiktj3() != null, TdmdjlbBsInfo::getShiktj3, bo.getShiktj3());
        lqw.eq(bo.getKengnstyzl3() != null, TdmdjlbBsInfo::getKengnstyzl3, bo.getKengnstyzl3());
        lqw.eq(bo.getShimd3() != null, TdmdjlbBsInfo::getShimd3, bo.getShimd3());
        lqw.eq(StringUtils.isNotBlank(bo.getQuyzh4()), TdmdjlbBsInfo::getQuyzh4, bo.getQuyzh4());
        lqw.eq(StringUtils.isNotBlank(bo.getQuywz4()), TdmdjlbBsInfo::getQuywz4, bo.getQuywz4());
        lqw.eq(bo.getQuysd4() != null, TdmdjlbBsInfo::getQuysd4, bo.getQuysd4());
        lqw.eq(bo.getShiqtszl4() != null, TdmdjlbBsInfo::getShiqtszl4, bo.getShiqtszl4());
        lqw.eq(bo.getShihtjsyszl4() != null, TdmdjlbBsInfo::getShihtjsyszl4, bo.getShihtjsyszl4());
        lqw.eq(bo.getShiknszl4() != null, TdmdjlbBsInfo::getShiknszl4, bo.getShiknszl4());
        lqw.eq(bo.getLiangsmd4() != null, TdmdjlbBsInfo::getLiangsmd4, bo.getLiangsmd4());
        lqw.eq(bo.getShiktj4() != null, TdmdjlbBsInfo::getShiktj4, bo.getShiktj4());
        lqw.eq(bo.getKengnstyzl4() != null, TdmdjlbBsInfo::getKengnstyzl4, bo.getKengnstyzl4());
        lqw.eq(bo.getShimd4() != null, TdmdjlbBsInfo::getShimd4, bo.getShimd4());
        lqw.eq(StringUtils.isNotBlank(bo.getHeh11()), TdmdjlbBsInfo::getHeh11, bo.getHeh11());
        lqw.eq(bo.getHezl11() != null, TdmdjlbBsInfo::getHezl11, bo.getHezl11());
        lqw.eq(bo.getHejstzl11() != null, TdmdjlbBsInfo::getHejstzl11, bo.getHejstzl11());
        lqw.eq(bo.getHejgtzl11() != null, TdmdjlbBsInfo::getHejgtzl11, bo.getHejgtzl11());
        lqw.eq(bo.getShuifzl11() != null, TdmdjlbBsInfo::getShuifzl11, bo.getShuifzl11());
        lqw.eq(bo.getGantzl11() != null, TdmdjlbBsInfo::getGantzl11, bo.getGantzl11());
        lqw.eq(bo.getHansl11() != null, TdmdjlbBsInfo::getHansl11, bo.getHansl11());
        lqw.eq(StringUtils.isNotBlank(bo.getHeh12()), TdmdjlbBsInfo::getHeh12, bo.getHeh12());
        lqw.eq(bo.getHezl12() != null, TdmdjlbBsInfo::getHezl12, bo.getHezl12());
        lqw.eq(bo.getHejstzl12() != null, TdmdjlbBsInfo::getHejstzl12, bo.getHejstzl12());
        lqw.eq(bo.getHejgtzl12() != null, TdmdjlbBsInfo::getHejgtzl12, bo.getHejgtzl12());
        lqw.eq(bo.getShuifzl12() != null, TdmdjlbBsInfo::getShuifzl12, bo.getShuifzl12());
        lqw.eq(bo.getGantzl12() != null, TdmdjlbBsInfo::getGantzl12, bo.getGantzl12());
        lqw.eq(bo.getHansl12() != null, TdmdjlbBsInfo::getHansl12, bo.getHansl12());
        lqw.eq(bo.getHanslpjz1() != null, TdmdjlbBsInfo::getHanslpjz1, bo.getHanslpjz1());
        lqw.eq(StringUtils.isNotBlank(bo.getHeh21()), TdmdjlbBsInfo::getHeh21, bo.getHeh21());
        lqw.eq(bo.getHezl21() != null, TdmdjlbBsInfo::getHezl21, bo.getHezl21());
        lqw.eq(bo.getHejstzl21() != null, TdmdjlbBsInfo::getHejstzl21, bo.getHejstzl21());
        lqw.eq(bo.getHejgtzl21() != null, TdmdjlbBsInfo::getHejgtzl21, bo.getHejgtzl21());
        lqw.eq(bo.getShuifzl21() != null, TdmdjlbBsInfo::getShuifzl21, bo.getShuifzl21());
        lqw.eq(bo.getGantzl21() != null, TdmdjlbBsInfo::getGantzl21, bo.getGantzl21());
        lqw.eq(bo.getHansl21() != null, TdmdjlbBsInfo::getHansl21, bo.getHansl21());
        lqw.eq(StringUtils.isNotBlank(bo.getHeh22()), TdmdjlbBsInfo::getHeh22, bo.getHeh22());
        lqw.eq(bo.getHezl22() != null, TdmdjlbBsInfo::getHezl22, bo.getHezl22());
        lqw.eq(bo.getHejstzl22() != null, TdmdjlbBsInfo::getHejstzl22, bo.getHejstzl22());
        lqw.eq(bo.getHejgtzl22() != null, TdmdjlbBsInfo::getHejgtzl22, bo.getHejgtzl22());
        lqw.eq(bo.getShuifzl22() != null, TdmdjlbBsInfo::getShuifzl22, bo.getShuifzl22());
        lqw.eq(bo.getGantzl22() != null, TdmdjlbBsInfo::getGantzl22, bo.getGantzl22());
        lqw.eq(bo.getHansl22() != null, TdmdjlbBsInfo::getHansl22, bo.getHansl22());
        lqw.eq(bo.getHanslpjz2() != null, TdmdjlbBsInfo::getHanslpjz2, bo.getHanslpjz2());
        lqw.eq(StringUtils.isNotBlank(bo.getHeh31()), TdmdjlbBsInfo::getHeh31, bo.getHeh31());
        lqw.eq(bo.getHezl31() != null, TdmdjlbBsInfo::getHezl31, bo.getHezl31());
        lqw.eq(bo.getHejstzl31() != null, TdmdjlbBsInfo::getHejstzl31, bo.getHejstzl31());
        lqw.eq(bo.getHejgtzl31() != null, TdmdjlbBsInfo::getHejgtzl31, bo.getHejgtzl31());
        lqw.eq(bo.getShuifzl31() != null, TdmdjlbBsInfo::getShuifzl31, bo.getShuifzl31());
        lqw.eq(bo.getGantzl31() != null, TdmdjlbBsInfo::getGantzl31, bo.getGantzl31());
        lqw.eq(bo.getHansl31() != null, TdmdjlbBsInfo::getHansl31, bo.getHansl31());
        lqw.eq(StringUtils.isNotBlank(bo.getHeh32()), TdmdjlbBsInfo::getHeh32, bo.getHeh32());
        lqw.eq(bo.getHezl32() != null, TdmdjlbBsInfo::getHezl32, bo.getHezl32());
        lqw.eq(bo.getHejstzl32() != null, TdmdjlbBsInfo::getHejstzl32, bo.getHejstzl32());
        lqw.eq(bo.getHejgtzl32() != null, TdmdjlbBsInfo::getHejgtzl32, bo.getHejgtzl32());
        lqw.eq(bo.getShuifzl32() != null, TdmdjlbBsInfo::getShuifzl32, bo.getShuifzl32());
        lqw.eq(bo.getGantzl32() != null, TdmdjlbBsInfo::getGantzl32, bo.getGantzl32());
        lqw.eq(bo.getHansl32() != null, TdmdjlbBsInfo::getHansl32, bo.getHansl32());
        lqw.eq(bo.getHanslpjz3() != null, TdmdjlbBsInfo::getHanslpjz3, bo.getHanslpjz3());
        lqw.eq(StringUtils.isNotBlank(bo.getHeh41()), TdmdjlbBsInfo::getHeh41, bo.getHeh41());
        lqw.eq(bo.getHezl41() != null, TdmdjlbBsInfo::getHezl41, bo.getHezl41());
        lqw.eq(bo.getHejstzl41() != null, TdmdjlbBsInfo::getHejstzl41, bo.getHejstzl41());
        lqw.eq(bo.getHejgtzl41() != null, TdmdjlbBsInfo::getHejgtzl41, bo.getHejgtzl41());
        lqw.eq(bo.getShuifzl41() != null, TdmdjlbBsInfo::getShuifzl41, bo.getShuifzl41());
        lqw.eq(bo.getGantzl41() != null, TdmdjlbBsInfo::getGantzl41, bo.getGantzl41());
        lqw.eq(bo.getHansl41() != null, TdmdjlbBsInfo::getHansl41, bo.getHansl41());
        lqw.eq(StringUtils.isNotBlank(bo.getHeh42()), TdmdjlbBsInfo::getHeh42, bo.getHeh42());
        lqw.eq(bo.getHezl42() != null, TdmdjlbBsInfo::getHezl42, bo.getHezl42());
        lqw.eq(bo.getHejstzl42() != null, TdmdjlbBsInfo::getHejstzl42, bo.getHejstzl42());
        lqw.eq(bo.getHejgtzl42() != null, TdmdjlbBsInfo::getHejgtzl42, bo.getHejgtzl42());
        lqw.eq(bo.getShuifzl42() != null, TdmdjlbBsInfo::getShuifzl42, bo.getShuifzl42());
        lqw.eq(bo.getGantzl42() != null, TdmdjlbBsInfo::getGantzl42, bo.getGantzl42());
        lqw.eq(bo.getHansl42() != null, TdmdjlbBsInfo::getHansl42, bo.getHansl42());
        lqw.eq(bo.getHanslpjz4() != null, TdmdjlbBsInfo::getHanslpjz4, bo.getHanslpjz4());
        lqw.eq(bo.getGanmd1() != null, TdmdjlbBsInfo::getGanmd1, bo.getGanmd1());
        lqw.eq(bo.getGanmd2() != null, TdmdjlbBsInfo::getGanmd2, bo.getGanmd2());
        lqw.eq(bo.getGanmd3() != null, TdmdjlbBsInfo::getGanmd3, bo.getGanmd3());
        lqw.eq(bo.getGanmd4() != null, TdmdjlbBsInfo::getGanmd4, bo.getGanmd4());
        lqw.eq(bo.getPingjgmd1() != null, TdmdjlbBsInfo::getPingjgmd1, bo.getPingjgmd1());
        lqw.eq(bo.getPingjgmd2() != null, TdmdjlbBsInfo::getPingjgmd2, bo.getPingjgmd2());
        return lqw;
    }

    /**
     * 新增土的密度记录
     */
    @Override
    public Boolean insertByBo(TdmdjlbBsInfoBo bo) {
        TdmdjlbBsInfo add = BeanUtil.toBean(bo, TdmdjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改土的密度记录
     */
    @Override
    @DealHeh
    public Boolean updateByBo(TdmdjlbBsInfoBo bo) {
        TdmdjlbBsInfo update = BeanUtil.toBean(bo, TdmdjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(TdmdjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除土的密度记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
